package com.wanji.protocol.api;

import io.netty.channel.ChannelPipeline;

public abstract class ProtocolTemplate implements Protocol {


    @Override
    public void init(ChannelPipeline pipeline) {
        initPipeline(pipeline);
        pipeline.addLast(createDecoder());
        pipeline.addLast(createEncoder());
    }

    @Override
    public Protocol clone() {
        try {
            return (Protocol) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    protected abstract DeviceMessageDecoder<?> createDecoder();

    protected abstract ByteBufEncoder<?> createEncoder();

    protected abstract void initPipeline(ChannelPipeline pipeline);
}
